'use serict'
//1
function indexOf(arr, item) {
    return arr.indexOf(item);
}

var x =indexOf(['A','B','C'],'C');
console.log(x);



//2
function sum(arr1)
{
    var sum=0;
    for (var index = 0; index < arr1.length; index++) {
       sum+= arr1[index];
    }
    return sum;
}
var a1=sum([1,2,3,4,5,6]);
console.log(a1);

//3
function remove(arr, item) {
    var result = [];
    arr.forEach(function(arrItem){
        if(item != arrItem){
            result.push(arrItem);
        }
    })
    return result;
}

console.log(remove([2,1,3],1));

//4
function removeWithoutCopy(arr, item) {
    while(arr.indexOf(item) != -1){
        arr.splice(arr.indexOf(item),1)
    }
    return arr;
}

console.log(removeWithoutCopy([1,2,5,3,4,3,4],3));


//5
function append(arr, item) {
    var result = [];
    arr.forEach(function(arrItem){
        result.push(arrItem);
    })
    result.push(item);
    return result;
}



//6
function adddel(arr){

    var del1=[];
    arr.forEach(function(arrItem){
        del1.push(arrItem);
    })
del1.pop();
return del1;
}
console.log(adddel([1,2,3,4]));


//7
function prepend(arr,item) {
var arr1=arr.concat();

arr1.unshift(item);
return arr1
}

    console.log(prepend([1,2],3));


//8
function cour(arr) {
    var arr1=arr.concat();
    arr1.shift();
    return arr1
}
console.log(cour([1,2,3]));

//9
function concat(arr1, arr2) {
    var currentArr1 = arr1.slice(0);
    var currentArr2 = arr2.slice(0);
    return currentArr1.concat(currentArr2)
}
console.log(concat([1],[2]));

//10
function insert(arr,item,index) {
    var arr1=arr.concat();
    arr1.splice(index, 0, item);
return arr1
}
console.log(insert([1,2,3],5,2));

//11
function count(arr, item) {
    var num = 0;
    for (let index = 0; index < arr.length; index++) {
        if (arr[index]==item) {
            num++
        }
        
    }
    return num;
}
console.log(count([1,2,3,1],1));

//12
function dup(arr) {
    var result = [];
    arr.forEach(function(item){
        if((arr.indexOf(item) != -1)&&(arr.indexOf(item) != arr.lastIndexOf(item))){
            if(result.indexOf(item) == -1){
                result.push(item)
            }
        }
    });
    return result;
}
console.log(dup([1,2,3,1,2,4]));

//13
function square(arr) {
    var result = arr.slice(0);
    result.forEach(function(item,index){
        result[index] = item * item;
    })
    return result;
}

console.log(square([1,2,3]));

//14
function xxx(arr,item) {
var x=[];
for (let index = 0; index < arr.length; index++) {
    if (arr[index]==item) {
        x.push(index)
    }
   
}
return x;
}
console.log(xxx([1,2,3,1,3,5,3],3));